package com.gxa.ssm340.controller;



import com.gxa.ssm340.common.R;
import com.gxa.ssm340.entity.dto.ExchangeGoodsDTO;
import com.gxa.ssm340.entity.dto.SubmitPointsDTO;
import com.gxa.ssm340.entity.dto.UserPointsDTO;
import com.gxa.ssm340.entity.pojo.Goods;
import com.gxa.ssm340.exception.BizException;
import com.gxa.ssm340.service.PointsCancelService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "PointsCancelController",tags = "积分核销管理接口")
@RestController
public class PointsCancelController {
    @Autowired
    private PointsCancelService pointsCancelService;
    @ApiOperation("搜索会员是否已注册")
    @PostMapping("/user/managerlogin")
    @ApiImplicitParam(name = "phone",value = "会员手机号",dataType = "String",required = true)
    public R searchByPhone(String phone) throws BizException {
        UserPointsDTO vo = pointsCancelService.getTotalPointsByPhone(phone);
        return R.success(vo);
    }
    @ApiOperation("获取所有的可兑换商品")
    @PostMapping("/mgr/goodsList")
    public R list(){
        List<Goods> allGoods = pointsCancelService.getAllGoods();
        return R.success(allGoods);
    }
    @ApiOperation("通过用户总积分实现兑换商品")
    @PostMapping("/mgr/userPointsExchange")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "用户手机号", dataType = "String", required = true),
            @ApiImplicitParam(name = "goodsId", value = "商品编号", dataType = "Integer", required = true)
    }
    )
    public R checkingCalculation(@RequestBody ExchangeGoodsDTO dto){
        Integer signal = pointsCancelService.addExchangeGoods(dto);
        if (signal<0){
            return R.failed();
        }
        return R.success();
    }
    @ApiOperation("提交会员购买商品的积分信息")
    @PostMapping("/mgr/userPointsGet")
    public R submitPointsToDataBase(@RequestBody SubmitPointsDTO dto){
        Integer integer = pointsCancelService.addPoints(dto);
        if (integer<0){
            return R.failed();
        }
        return R.success();
    }
}
